package com.yootk;
import java.util.concurrent.atomic.AtomicStampedReference;
class Book{
    private String title;
    private double price;

    //无参构造方法
    public Book(){
    }

    //有参构造方法
    public Book(String title, double price){
        this.title = title;
        this.price = price;
    }

    //getter和setter方法
    public String getTitle(){
        return title;
    }

    public void setTitle(String title){
        this.title = title;
    }

    public double getPrice(){
        return price;
    }

    public void setPrice(double price){
        this.price = price;
    }

    @Override
    public String toString(){
        return "【图书】名称 = " + this.title + "、价格 = " + this.price;
    }
}
public class YootkDemo2 {
    public static void main(String[] args) throws Exception{
        Book book = new Book("Java就业编程实战",67.8);
        AtomicStampedReference<Book> ref = new AtomicStampedReference<Book>(book,1);
        ref.compareAndSet(book,new Book("Spring就业编程实战",67.8),1,2);
        System.out.println(ref.getReference());
        System.out.println("当前版本号：" + ref.getStamp());
    }
}
